package mytrain.kirayous;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.util.ResourceBundle;

public class JedisUtils {

    private static JedisPool jedisPool=null;
    /*思考一下为什么这里要使用静态代码块*/
    static
    {


      JedisPoolConfig jedisPoolConfig=new JedisPoolConfig();



      ResourceBundle resourceBundle=ResourceBundle.getBundle("jedis");

      String host=resourceBundle.getString("jedis.host");
      int port=Integer.parseInt(resourceBundle.getString("jedis.port"));

      int maxIdle=Integer.parseInt(resourceBundle.getString("jedis.maxIdle"));
      int maxTotal=Integer.parseInt(resourceBundle.getString("jedis.maxTotal"));

      jedisPoolConfig.setMaxIdle(maxIdle);
      jedisPoolConfig.setMaxTotal(maxTotal);

      jedisPool=new JedisPool(jedisPoolConfig,host,port);

    }
    public static Jedis getJedisConnection()
    {
        return jedisPool.getResource();
    }
}
